package com.example.no1admin.controller;

import com.example.no1admin.pojo.dto.comments.CommentsAddNewDTO;
import com.example.no1admin.pojo.vo.comments.CommentsListItemVO;
import com.example.no1admin.service.ICommentsService;
import com.example.no1admin.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "评论管理模块")
@RequestMapping("/comments")
@Slf4j
@RestController
public class CommentsController {
    @Autowired
    ICommentsService commentsService;

    @ApiOperation("创建评论")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@RequestBody CommentsAddNewDTO commentsAddNewDTO){
        log.debug("接受到的请求参数:{}",commentsAddNewDTO);
        commentsService.addNew(commentsAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除评论")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult deleteById(@PathVariable Long id){
        log.debug("接收到删除评论的请求");
        commentsService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("评论列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult list(){
        log.debug("接收到查询评论列表的请求");
        List<CommentsListItemVO> list = commentsService.list();
        return JsonResult.ok(list);
    }
}
